﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNet.Common.NHibernateUtil;
using ZLCMS.Data.Model;
using NHibernate;
using NHibernate.Criterion;

namespace ZLCMS.Web.UC
{
    public partial class UC_PcProductCategoryNav : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string GetSearchCategoryItemHtml(int categoryId)
        {
            string htmStr = "";
            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                ShopCategory category = session.CreateCriteria<ShopCategory>().Add(Expression.Eq("Id", categoryId)).UniqueResult<ShopCategory>();

                if (category == null)
                {
                    return "";
                }
                htmStr = "<a href='/Product/ProductList.aspx?categoryid=" + categoryId + "' >" + category.CategoryName + "</a><div class='wrap'>";

                IList<ShopSearchPropertyGroup> propertyList = session.CreateCriteria<ShopSearchPropertyGroup>().Add(Expression.Eq("CategoryId", categoryId)).List<ShopSearchPropertyGroup>();
                foreach (ShopSearchPropertyGroup property in propertyList)
                {
                    htmStr += "<p><span>" + property.PropertyValue + "</span></p> <ul class='wrap_list'>";
                    IList<ShopSearchPropertyItem> propertyItemList = session.CreateCriteria<ShopSearchPropertyItem>().Add(Expression.Eq("SearchPropertyId", property.Id)).List<ShopSearchPropertyItem>();
                    for (int i = 0; i < propertyItemList.Count; i++)
                    {
                        htmStr += "<li ";
                        if (i == 0)
                        {
                            htmStr += " class='fir'";
                        }
                        htmStr += "><a href='/Product/ProductList.aspx?categoryid=" + category.Id + "&" + property.Id + "=" + propertyItemList[i].Id + "'>" + propertyItemList[i].PropertyName + "</a></li>";
                    }
                    htmStr += "<div class='clear'></div></ul>";
                }
                htmStr += "  </div>";
                return htmStr;
            }
        }
    }
}